﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.ComponentModel;

namespace Light.Utility
{
    /// <summary>
    /// 摘要:
    /// 　　指示一个属性可用于JSON序列化。
    /// </summary>
    [Serializable]
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    [ComVisible(true)]
    public sealed class JsonSerializeAttribute : Attribute
    {
        private string _key = string.Empty;
        private bool _ignoreMobile = false;


        /// <summary>
        /// 初始化新实例
        /// </summary>
        public JsonSerializeAttribute()
            : base()
        {
        }

        /// <summary>
        /// 初始化新实例
        /// </summary>
        /// <param name="key">JSON数据的Key</param>
        public JsonSerializeAttribute(string key)
            : base()
        {
            this.Key = key;
        }


        /// <summary>
        /// 初始化新实例
        /// </summary>
        /// <param name="key">JSON化时，是否忽略此属性</param>
        public JsonSerializeAttribute(bool ignoreMobile)
            : base()
        {
            this._ignoreMobile = ignoreMobile;
        }

        /// <summary>
        /// JSON数据{"key":"value"}中的key
        /// </summary>
        public string Key
        {
            get { return this._key; }
            set { this._key = value; }
        }

        /// <summary>
        /// 是否忽略移动设备
        /// </summary>
        public bool IgnoreMobile
        {
            get { return _ignoreMobile; }
            set { _ignoreMobile = value; }
        }

    }


    /// <summary>
    /// 摘要:
    /// 　　指示一个属性不可用于JSON序列化。
    /// </summary>
    [Serializable]
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    [ComVisible(true)]
    public sealed class NonJsonSerializeAttribute : Attribute
    {
        /// <summary>
        /// 初始化新实例
        /// </summary>
        public NonJsonSerializeAttribute()
            : base()
        {
        }
    }
}